package com.leolian.spring02.activemq;

import javax.jms.JMSException;  
import javax.jms.Message;  
import javax.jms.Session;  
  


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;  
import org.springframework.jms.core.MessageCreator;  
import org.springframework.stereotype.Component;
  
/** 
 * @description 生产者 
 */ 
@Component
public class Lesson4Producer {
	@Autowired
    private JmsTemplate jmsTemplate;  
    
    public JmsTemplate getJmsTemplate() {  
        return jmsTemplate;  
    }  
    
    //使用JMSTemplate发送消息  
    public void send(final String msg) {  
        jmsTemplate.send(new MessageCreator() {  
            public Message createMessage(Session session) throws JMSException {  
                return session.createTextMessage(msg);  
            }  
        });  
    }  
  
}